package com.guotd.ticketSystemPlus.config;

import com.guotd.ticketSystemPlus.tools.FlightTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.guotd.ticketSystemPlus.constants.SystemConstants.SERVICE_SYSTEM_PROMPT;

@Configuration
public class CommonConfiguration {

    /*@Bean
    public ChatMemory chatMemory(){
         return MessageWindowChatMemory.builder().build();
    }*/

    @Bean
    public ChatClient chatClient(OpenAiChatModel model, ChatMemory chatMemory , FlightTools flightTools){
        return ChatClient
                .builder(model)  //创建ChatClient工厂实例
                .defaultSystem(SERVICE_SYSTEM_PROMPT)  //system设定身份
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),    //记录日志
                        MessageChatMemoryAdvisor.builder(chatMemory).build()  //记忆功能
                )
                .defaultTools(flightTools)
                .build();
    }
}
